package com.edu.app.mapper.linkmappers;

import com.edu.app.bean.core.SysContract;
import com.edu.app.bean.core.SysUser;
import com.edu.app.bean.linkbeans.SysUserContract;
import com.edu.app.util.AppBaseMapper;

import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SysUserContractMapper extends AppBaseMapper<SysUserContract> {
    @Select("SELECT t3.* FROM S_USER t1 INNER JOIN S_USER_CONTRACT t2 on t1.ID = t2.USER_ID INNER " +
            "JOIN S_CONTRACT t3 on t2.CONTRACT_ID = t3.ID " +
            "WHERE t1.id = #{id}")
    List<SysContract> getContractByUserId(Integer id);

    @Select("SELECT t1.* FROM S_USER t1 INNER JOIN S_USER_CONTRACT t2 on t1.ID = t2.USER_ID INNER " +
            "JOIN S_CONTRACT t3 on t2.CONTRACT_ID = t3.ID " +
            "WHERE t3.id = #{id}")
    List<SysUser> getUserByContractId(Integer id);

    @Select("DELETE FROM S_USER_CONTRACT WHERE CONTRACT_ID = #{id}")
    Integer deleteUserContractByContractId(Integer id);

    @Select("DELETE FROM S_USER_CONTRACT WHERE USER_ID = #{id}")
    Integer deleteUserContractByUserId(Integer id);
}
